import httpInstance from "../utils/http";

//因为参数这里采用了解构赋值的方法， 所以在调用这个方法传参的时候，必须传入一个对象，里面还需要包含这三个字段
/**
 * @description 密码登录
 * @param phone 手机号
 * @param password 密码
 * @param captcha 验证码
 * @returns 
 * 
 */
export function passwordLoginApi({
  phone,
  password,
  captcha,
  captchaId
}) {
  return httpInstance.post("/user/passwordLogin", {
    phone,
    password,
    captcha,
    captchaId
  });
}

/**
 * @description 获取验证码
 * @param null
 * @returns
 */
export function getCaptchaApi(id) {
  return httpInstance({
    url: 'user/getCaptcha',
    params: {
      id
    },
    responseType: 'blob' //设置响应类型为blob以正确的处理二进制数据
  })
}

/**
 * @description 获取短信验证码
 * @param null
 * @returns
 */
export function getMessageCaptchaApi({
  captchaType,
  phone
}) {

  return httpInstance({
    url: 'user/getMessageCaptcha',
    params: {
      captchaType,
      phone
    }
  })
}


/**
 * @description 短信登录
 * @param phone 手机号
 * @param captcha 验证码
 * @returns
 */
export function messageLoginApi({
  phone,
  messageCaptcha
}) {
  return httpInstance.post("/user/messageLogin", {
    phone,
    messageCaptcha
  });
}


/**
 * @description 注册接口
 * @param phone 手机号
 * @param password 密码
 * @param messageCaptcha 短信验证码
 * @returns
 */
export function registerApi({
  phone,
  password,
  confirmPassword,
  messageCaptcha
}) {
  return httpInstance.post("/user/register", {
    phone,
    password,
    confirmPassword,
    messageCaptcha
  })
}

/**
 * @description 忘记密码图形验证码接口
 * @param captcha 验证码
 * @returns
 */
export function forgetValidateApi(captcha, captchaId) {
  return httpInstance({
    type: 'get',
    url: 'user/forgetValidate',
    params: {
      captcha,
      captchaId
    }
  })
}

/**
 * @description 重置密码接口
 * @param phone 手机号
 * @param password 密码
 * @param confirmPassword 确认密码
 * @param messageCaptcha 短信验证码
 * @returns
 */
export function resetPasswordApi({
  phone,
  password,
  confirmPassword,
  messageCaptcha
}) {
  return httpInstance.post("/user/resetPassword", {
    phone,
    password,
    confirmPassword,
    messageCaptcha
  })
}



/**
 * @description 获取重置密码token接口
 * @param token 重置密码token
 * @returns
 */
export function checkResetTokenApi(
  token
) {
  console.log(token);

  return httpInstance({
    type: 'get',
    url: 'user/getResetToken',
    params: {
      token
    }
  })
}



/**
 * @description 获取用户信息接口
 * @param userId 用户id
 * @returns
 */
export function getExperienceApi(userId) {
  return httpInstance({
    type: 'get',
    url: 'experience/getExperience',
    params: {
      userId
    }
  })
}